-------------------------------------------------------------------------------
--	 File name: cl_init.lua
--		Author: Sploder
-- 		  Date: 03/01/2010
-- Description: This file contains the definitions for client-side methods for
--					Sakuya's basic weapon.
--
-------------------------------------------------------------------------------

include ("shared.lua")

-- Swep characteristics:
SWEP.Category		= "Danmaku"
SWEP.PrintName		= "Scarlet Knives"
SWEP.Author			= "Sploder"
SWEP.Instructions	= "Press ATTACK to throw knives; press ATTACK2 to activate a spellcard."
SWEP.Slot			= 1
SWEP.SlotPos		= 0
SWEP.DrawAmmo		= false


SWEP.WepSelectIcon = surface.GetTextureID("HUD/killicons/sakuya")
SWEP.BounceWeaponIcon = false

--[[SWEP.shoottime	= 0
SWEP.cooldown	= 0.2
SWEP.lastfired			= 0
SWEP.lastfiredsystime	= 0
]]

-------------------------------------------------------------------------------
--	  Function: SWEP:PrimaryAttack()
-- Description: This function is called when the weapon's owner press attack1.
-------------------------------------------------------------------------------
function SWEP:PrimaryAttack()
end

-------------------------------------------------------------------------------
--	  Function: SWEP:SecondaryAttack()
-- Description: This function is called when the weapon's owner presses attack2
-------------------------------------------------------------------------------
function SWEP:SecondaryAttack()
	-- Just to insure it doesn't make that clicking noise.
end

-------------------------------------------------------------------------------
--	  Function: SWEP:DrawWorldModel()
-- Description: This function is called to draw the world model.
-------------------------------------------------------------------------------
--[[function SWEP:DrawWorldModel()
	-- Draw the model, as usual...
	self.Weapon:DrawModel()
end]]

-------------------------------------------------------------------------------
--	  Function: SWEP:DrawHUD()
-- Description: This function is called when every frame to draw the HUD.
--					You want to only draw here; nothing else.
-------------------------------------------------------------------------------
function SWEP:DrawHUD()
	-- Draw the spirit gauge.
	local startx = ScrW() * 0.40				-- The position of the left edge of the rectangle.
	local starty = ScrH() * 0.90				-- The position of the top edge of the rectangle.
	local width = (ScrW() * 0.95) - startx		-- The width of the rectangle.
	local height = (ScrH() * 0.96) - starty		-- The height of the rectangle.
	local power = self:GetNetworkedFloat("spiritPower")	-- The amount of power the player has.
	
	local color1	= Color(237, 038, 036, 128)
	local color2	= Color(255, 126, 000, 128)
	local color3	= Color(255, 242, 000, 128)
	local colorf	= Color(255, 250, 206, 160)
	
	-- If spellcard3 is active, change the colors of the panels.
	if (self:GetNWInt("scactive") == 3)
	then
		local sc3color	= Color(132, 255, 249, 128)
		color1 = sc3color
		color2 = sc3color
		color3 = sc3color
	end
	
	-- Draw the first section. ------------------
	local x = startx					-- The left edge of this section.
	-- If we have less than 33 power, make it one color.
	if (power < 33)	
	then
		surface.SetDrawColor(color1.r, color1.g, color1.b, color1.a)
	-- Otherwise, make the color a different color.
	else
		surface.SetDrawColor(colorf.r, colorf.g, colorf.b, colorf.a)
	end
	-- Draw a rectangle with the specified properties.
	surface.DrawRect(x, starty, width * (1/3), height)
	
	-- Draw the second section. -----------------
	x = x + (width * (1/3))
	-- If we have less than 66 power, make it one color.
	if (power < 66)	
	then
		surface.SetDrawColor(color2.r, color2.g, color2.b, color2.a)
	-- Otherwise, make the color a different color.
	else
		surface.SetDrawColor(colorf.r, colorf.g, colorf.b, colorf.a)
	end
	-- Draw a rectangle with the specified properties.
	surface.DrawRect(x, starty, width * (1/3), height)
	
	-- Draw the third section. ------------------
	x = x + (width * (1/3))
	-- If we have less than 100 power, make it one color.
	if (power < 100)
	then
		surface.SetDrawColor(color3.r, color3.g, color3.b, color3.a)
	-- Otherwise, make the color a different color.
	else
		surface.SetDrawColor(colorf.r, colorf.g, colorf.b, colorf.a)
	end
	-- Draw a rectangle with the specified properties.
	surface.DrawRect(x, starty, width * (1/3), height)
	
	-- Draw the outlines. -----------------------
	surface.SetDrawColor(255, 255, 255, 255)
	surface.DrawOutlinedRect(startx, starty, width, height)
	
	surface.SetDrawColor(0, 0, 0, 255)
	surface.DrawLine(startx + (width * (1/3)), starty, startx + (width * (1/3)), starty + height)
	surface.DrawLine(startx + (width * (2/3)), starty, startx + (width * (2/3)), starty + height)
	
	-- Draw the arrow. --------------------------
	local pos = power / 100
	local arrowSize = height / 2
	x = Lerp(pos, startx, startx + width) - (arrowSize / 4)
	surface.SetDrawColor(255, 255, 255, 255)
	surface.SetTexture(surface.GetTextureID( "sprites/danmaku/spiritArrow"))
	surface.DrawTexturedRect(x, starty, arrowSize / 2, arrowSize)
	
	-- If we currently have a spellcard timer active, then print out the time remaining.
	local timer = self:GetNetworkedInt("spellcardTimer")
	local timeleft = math.Round(timer - CurTime())
	if (timeleft > 0)
	then
		local startColor	= Color(253, 254, 192, 255)
		local endColor		= Color(240, 052, 026, 255)
		local percent		= timeleft / 40
		
		surface.SetTextColor(Lerp(percent, endColor.r, startColor.r),
								Lerp(percent, endColor.g, startColor.g),
								Lerp(percent, endColor.b, startColor.b), 255)

		surface.SetTextPos(ScrW() * 0.9, ScrH() * 0.02)
		surface.SetFont("CIRNOSCALED")
		surface.DrawText(tostring(timeleft))
	end
	
	-- Draw the spellcard panel. ----------------
	x = startx + (width * 0.90)
	surface.SetTexture(surface.GetTextureID("sprites/danmaku/scholder"))
	surface.DrawTexturedRect(x, starty - (height * 2.36), height * 1.5, height * 3)
	
	-- If a spellcard isn't currently active, draw the currently available spellcard.
	if (timeleft <= 0)
	then
		local spellcardTex = Material("sprites/danmaku/sakuya/spellcards")
		local fr = 0
		if (power >= 33 && power < 66)
		then
			fr = 0
		elseif (power >= 66 && power < 100)
		then
			fr = 1
		elseif (power >= 100)
		then
			fr = 2
		end
		spellcardTex:SetMaterialInt("$frame", fr)
		surface.SetMaterial(spellcardTex)
		if (power >= 33)
		then
			surface.DrawTexturedRect(x, starty - (height * 2.36), height * 1.5, height * 3)
		end
	end
end